package com.zang.hash;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author ZVerify
 * @since 2022/10/12 19:55
 * @see <a href="https://leetcode.cn/problems/find-all-anagrams-in-a-string/">...</a>
 **/
public class 找到字符串中所有字母异位词 {

    public List<Integer> findAnagrams(String s, String p) {

        ArrayList<Integer> list = new ArrayList<>();

        int dowLength = p.length();

        int left = 0;

        char[] chars = p.toCharArray();
        Arrays.sort(chars);

        while (dowLength<s.length()){
            char[] array = s.substring(left, dowLength).toCharArray();
            Arrays.sort(array);
            if (Arrays.equals(array, chars)){
                list.add(left);
            }
            dowLength++;
            left++;
        }

        return list;

    }
}
